package users

import (
	"api/internal/respons"
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateAchievementLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateAchievementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAchievementLogic {
	return &CreateAchievementLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateAchievementLogic) CreateAchievement(req *types.CreateAchievementRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	achievement, err := l.svcCtx.UserRpc.CreateAchievement(l.ctx, &userclient.CreateAchievementRequest{
		UserId:            req.UserId,
		RuleId:            req.RuleId,
		AchievementName:   req.AchievementName,
		AchievementDesc:   req.AchievementDesc,
		AchievementImages: req.AchievementImages,
		IsLighted:         req.IsLighted,
		LightedTime:       req.LightedTime,
		Status:            req.Status,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}
	return respons.Success(achievement), nil
}
